package com.pdf.utils;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

public final class FileUtil {

    /**
     * 流转换为字节数组
     *
     * @param inputStream
     * @return
     */
    public static byte[] toByteArray(InputStream inputStream) {
       try {
           ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
           byte[] buffer = new byte[1024]; // 你可以根据需要调整缓冲区的大小
           int bytesRead;

           // 读取InputStream的内容到ByteArrayOutputStream
           while ((bytesRead = inputStream.read(buffer)) != -1) {
               byteArrayOutputStream.write(buffer, 0, bytesRead);
           }

           // 将ByteArrayOutputStream的内容转换为byte数组
           return byteArrayOutputStream.toByteArray();
       } catch (IOException e) {
           e.printStackTrace();
       }
       return null;
    }
}
